package com.meixiang.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.ShareList;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：黑哥 on 2016/7/6 15:38
 */
public class GrildDialogAdapter extends RecyclerView.Adapter<GrildDialogAdapter.ViewHolder> {

    private  List<ShareList> shareList=new ArrayList<>();
    private Context context;

    private Activity mActivity;

    public GrildDialogAdapter(Context context) {
        this.context = context;

    }
    public void setData(List<ShareList> shareList) {
        this.shareList = shareList;
        notifyDataSetChanged();
    }


    public void clear() {
        this.shareList.clear();
        this.notifyDataSetChanged();
    }



    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_grild_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

        if (mListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(holder.itemView, position);

                }
            });
        }

        holder.mIvShare.setBackgroundResource(shareList.get(position).getSharedId());
        holder.mTvShare.setText(shareList.get(position).getSharedPlatform());
    }

    /**
     * 单击事件监听器
     */
    private onItemClickListener mListener = null;

    public void setOnItemClickListener(onItemClickListener listener) {
        mListener = listener;
    }

    public interface onItemClickListener {

        /**
         * 点赞点击事件
         *
         * @param v
         * @param position
         */
        void onItemClick(View v, int position);


    }

    @Override
    public int getItemCount() {
        return shareList.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_share)
        ImageView mIvShare;
        @Bind(R.id.tv_share)
        TextView mTvShare;





        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
